package com.android.itiraf;
 
import java.util.ArrayList;

import com.google.ads.*;
import android.app.Activity;
import android.database.Cursor;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;
 
public class ShowDb extends Activity {
    private Database db;
    int i;
   ArrayList<String> list ;
   TextView tv1,tv2,tv3,tv4;
   AdView adView ;
   int current;

   @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    	
        db = new Database(this,"itiraflar");
        list = new ArrayList<String>();
        tv1 = (TextView) findViewById(R.id.textView1);
        tv2 = (TextView) findViewById(R.id.textView2);
        tv3 = (TextView) findViewById(R.id.textView4);
        tv4 = (TextView) findViewById(R.id.textView6);
        Bundle bndl = getIntent().getExtras();
		String [] ktgr = {bndl.getString("kategori")};
    	
        Cursor c =db.getRows(ktgr);
		startManagingCursor(c);
		list.clear();
		db.fillArrayList(c,list);
		if(!list.isEmpty()){
		tv1.setText(list.get(0));
		tv2.setText(list.get(1));
        current++;
        setCurrent();
		}
		else{
			tv1.setText("Üzgünüm");
			tv2.setText("Bu kategoride itiraf bulunmamaktadır.");	
			
		}
		i=3;

        tv4.setText(""+list.size()/3);
       
        Button bt1 = (Button) findViewById(R.id.imageButton1);
	       
	        bt1.setOnClickListener(new View.OnClickListener() {
				
				@Override
				public void onClick(View v) {
                     i=i-6;
					if(i>=0){
					tv1.setText(list.get(i++));
					 tv2.setText(list.get(i++));
					 i++;
					 current--;
					 setCurrent();
					}
					else
						i=3;
						}
			});
		
		
	        Button bt2 = (Button) findViewById(R.id.imageButton2);
       
        bt2.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				if(list.size()>i){
				tv1.setText(list.get(i++));
				 tv2.setText(list.get(i++));
				 i++;
				 current++;
				 setCurrent();
			}
				else
					i=list.size();
			}
		});
        Button bt3 = (Button) findViewById(R.id.button3);
        bt3.setText("Menu");
        bt3.setOnClickListener(new View.OnClickListener() {
			
			@Override
			public void onClick(View v) {
				finish();
			}
		});
   }
   public void setCurrent(){
	  tv3.setText(""+current);
   }
}
    

    
  
 